//
//  WaitUtility.m
//  Demo
//
//  Created by william mu on 12-8-2.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "WaitUtility.h"

void iCAFRunLoop()
{
    
    NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
    
    [runLoop runMode:UITrackingRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    [runLoop runMode:NSDefaultRunLoopMode  beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    
}

void activeWait(NSTimeInterval time)
{
    NSTimeInterval lastTick = [[NSDate date] timeIntervalSince1970];    
    while (YES) {
        iCAFRunLoop();
        NSTimeInterval timeElapsed = [[NSDate date] timeIntervalSince1970] - lastTick;
        if(timeElapsed >= time){
            break;
        }
        
    }
}


